package com.task.controller;

import com.common.general.PageAttribute;
import com.common.general.ResponseResult;
import com.task.pojo.Task;
import com.task.service.TaskService;
import com.task.vo.TaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2024年12月23日
 */
@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @RequestMapping("/find-all")
    public ResponseResult<Task> findAll() {
        return ResponseResult.success(200, "", taskService.list());
    }

    @RequestMapping("/page-find")
    public ResponseResult<Task> pageFind(String pageNum, String pageSize) {

        Integer currentPage = PageAttribute.PAGE_NUM;
        Integer currentSize = PageAttribute.PAGE_SIZE;

        if (!ObjectUtils.isEmpty(pageNum)) {
            currentPage = Integer.valueOf(pageNum);
        }
        if (!ObjectUtils.isEmpty(pageSize)) {
            currentSize = Integer.valueOf(pageSize);
        }

        return ResponseResult.success(200, "", taskService.pageFind(currentPage, currentSize));
    }

    @RequestMapping("query-page-find")
    public ResponseResult<Task> queryPageFind(@RequestBody TaskVo taskVo, String pageNum, String pageSize) {

        Integer currentPage = PageAttribute.PAGE_NUM;
        Integer currentSize = PageAttribute.PAGE_SIZE;

        if (!ObjectUtils.isEmpty(pageNum)) {
            currentPage = Integer.valueOf(pageNum);
        }
        if (!ObjectUtils.isEmpty(pageSize)) {
            currentSize = Integer.valueOf(pageSize);
        }

        return new ResponseResult(200, "", taskService.queryPageFind(taskVo, currentPage, currentSize));
    }

    @RequestMapping("1112")
    public ResponseResult<Task> queryPageFind(@RequestBody TaskVo taskVo) {
        return null;
    }

}
